package com.pine.dcts.taskScheduling.job;

import com.alibaba.datax.common.util.Configuration;
import com.pine.dcts.DctsEngine;
import com.pine.dcts.common.DctsException;
import com.pine.dcts.config.DctsConfig;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

/**
 * 可以串行执行datax任务
 */
@Setter
@Getter
@Slf4j
///保存在JobDataMap传递的参数,当你要一个计数器的时候,详情可参见以下这个例子.
@PersistJobDataAfterExecution
//保证多个任务间不会同时执行.所以在多任务执行时最好加上
@DisallowConcurrentExecution
public class StateDataxJob extends AbstractJob{

    private Integer  jobId;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("当前线程名字是：{}",Thread.currentThread().getName());
        Configuration configuration =  DctsConfig.jobConfigCenter.get(String.valueOf(jobId));
        if(configuration==null){
            throw new DctsException("当前job配置不存在");
        }
        DctsEngine engin = new DctsEngine();
        engin.start(configuration.toJSON());
        log.info("当前线程名字是：{}",Thread.currentThread().getName());
    }
}
